﻿using System;
using BlockLogic.Impl.Blocks.Checker.Enum;
using ComputationalCore.Helper;

namespace BlockLogic.Impl.Blocks.Checker.Strategy
{
    class GaussianChecking : CheckingStrategy
    {
        //private const double EXACTNESS = 0.001;

        public double M { get; set; }
        public double Sigma { get; set; }

        public GaussianChecking()
        {
            M = 0;
            Sigma = 1;
        }

        public GaussianChecking(double m, double sigma)
        {
            _type = CheckerType.GAUSSIAN;
            M = m;
            Sigma = sigma;
        }
/*
        private double f(double t)
        {
            return Math.Exp(-Math.Pow(t, 2) / 2);
        }


        public double LaplaceFunction(double x, double eps)
        {
            return (new CalculateHelper.Function(f).Integrate(eps, 0, x)) / Math.Sqrt(2 * Math.PI);
        }
*/

        protected override double DistributionFunctionValue(double x)
        {
            x -= M;
            x /= Sigma;
            //return -0.5 + LaplaceFunction((x - _m) / _sigma, EXACTNESS);
            return 1.0 / 2 * (1 + SpecialFunction.erf(x / Math.Sqrt(2)));
        }
/*
        public double Erf(double x)
        {
            Func<double, double> f = y => Math.Exp(-y * y);
            var value = new CalculateHelper.Function(f).Integrate(EXACTNESS, 0, x);
            return 2.0 / Math.Sqrt(Math.PI) * value;
        }*/
    }
}
